follow below steps
1) in your block file
namespace Mageplaza\HelloWorld\Block;
class HelloWorld extends \Magento\Framework\View\Element\Template
{
protected $_storeManager;
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Store\Model\StoreManagerInterface $storeManager,
array $data = []
)
{
$this->_storeManager = $storeManager;
parent::__construct($context, $data);
}
/**
* Get Store code
*
* @return string
*/
public function getStoreCode()
{
return $this->_storeManager->getStore()->getCode();
}
2) in your phtml file
<script type="text/x-magento-init">
{
"*": {
"Magento_Ui/js/core/app": {
"components": {
"yourWidget": {
"storeCode": "<?php echo $block->getStoreCode(); ?>"
}
}
}
}
}
</script>
3) in your js file or define same into phtml file as you wish
define(['uiComponent'], function(Component) {
'use strict';
return Component.extend({
initialize: function() {
this._super();
console.log(this.storeCode);
}
});
});